1. Field of the Invention
The invention relates to the field of computer microcontrollers and more particularly to the field of interrupt handling in a microcontroller environment.
2. Description of Background Art
Microcontrollers are microprocessors integrated with peripherals on a single integrated circuit. They are compact in size and yet retain the computational power of traditional microprocessors, allowing them to be used in a multitude of applications. For example, in a single household, microcontrollers are a part of microwave ovens, televisions, calculators, remote controls, clocks, etc. In a microwave oven, for example, the microcontroller senses the settings keyed in by the user and heats up the food for the set time interval and power level. The microcontroller keeps track of real time and produces a beep to notify the user when the heating is done. The microcontroller also displays the status of the microwave oven on a suitable display, typically an LCD or LED.
Every car has about twenty microcontrollers. In a car, they are used in the engine control modules, the antilock braking systems, the sound systems, the airbags, and automobile suspension control modules. In antilock braking systems, the microcontroller monitors the rotational speed of the tires through sensors attached to the tires. When the driver applies the brakes, the microcontroller determines whether any of the tires have locked. If any of the tires are locked, the microcontroller releases the brakes for that tire through a servo-mechanical device coupled to the brakes. Thus, the driver is able to steer the car during emergency braking situations without fear of having the tires lock and causing the car to skid or turn over.
A modem semiconductor microcontroller is basically a low-cost computer adapted to provide rapid solutions to external events after intensive computation. The microcontroller senses the happening of external events through signals received at input ports, and transmits responses to the events through its output ports. In order to provide this functionality, a typical microcontroller employs an on-chip Programmable Read Only Memory (PROM) to store its instructions, an on-chip data RAM to store the data temporarily, a Central Processing Unit (CPU) to execute the instructions stored in the PROM, an oscillator driver to generate the system clock, and other application-specific peripherals such as timers, interrupt handlers, watchdogs, analog comparators, etc.
If important events occur during the execution of the normal flow of program, the microcontroller must be able to respond quickly. In the microwave oven example, if a metal container is placed within the oven and the oven begins heating, the microcontroller must interrupt the heating before the metal container causes sparks or a fire in the oven. In the antilock braking example, applying the brakes interrupts the monitoring function of the microcontroller and forces it to immediately determine whether any of the tires have locked. As can be seen, an important design criterion for microcontrollers is the ability of the microcontroller to respond to external events as quickly as possible.
An interrupt mechanism is implemented in modern 8-bit ALU microcontrollers to provide a means for departing from the normal flow of program execution in response to an external event. In conventional systems, the interrupt logic of the microcontroller temporarily stops the normal flow of program execution and causes a separate interrupt service routine to be executed. After the interrupt has been serviced, execution continues with the next instruction in the main program that would normally have been executed following the point of interruption. In order to continue normal execution of the main program, however, certain critical data regarding the state of the microcontroller prior to servicing the interrupt routine must be known.
Conventional microcontroller interrupt handling designs use program code to save and retrieve the current state of the microcontroller to and from memory. The use of this code requires critical bandwidth to execute, slowing down interrupt response and recovery time. Additionally, this design requires the use of extra RAM registers to store the state information while the interrupt routine is being executed.
Below is an example of code currently required to initiate an interrupt service routine:
; Interrupt Service routine entry ; Interrupt entry, save context intentry movwfwsave ; Save the W register into WSAVE movf status, 0 ; Save the STATUS register into W movwfstatussave ; Move from W into STATUSSAVE ; (Z flag was affected, but after STATUS read) movf fsr, 0 ; Save the FSR register into W movwffsrsave ; Move from W into FSRSAVE (MAIN CODE) ; Main interrupt code which affects W, STATUS, ; and FSR ; Get ready to exit Interrupt Service routine, ; restore context movf fsrsave, 0 ; Move FSRSAVE into W movwffsr ; Restore FSR from W movf statussave, 0 ; Move STATUSSAVE into W movwfstatus ; Restore STATUS from W swapf wsave, 1 ; Swap WSAVE so that it can be un-swapped swapf wsave, 0 ; Move data back into W without affecting ; STATUS's Z flag reti ; return from interrupt (program counter is restored)
Executing the above code may take thirty to forty clock cycles, making conventional microcontrollers ineffective when external events require immediate responses. Thus, there is needed a system and method for quickly and efficiently handling interrupts in a microcontroller environment which does not require the use of expensive memory.